import "babel-polyfill" 
import Vue from 'vue'
import App from './App.vue'
import router from './router/router'
import store from './store/store'
import './registerServiceWorker'
import 'amfe-flexible/index.js' 
import axios from './utils/axios'
import Bridge from './plugins/jsBridge.js'
/* eslint-disable */
import $ from 'jquery';
import {Toast , List} from "vant";

/* eslint-disable */
// Vue.use(Toast).use(List);  

Vue.config.productionTip = false;
Vue.prototype.$http = axios;
Vue.prototype.$bridge = Bridge ;
Vue.prototype.$setgoindex = function () {
  if (window.history.length <= 1) {
    if (location.href.indexOf('?') === -1) {
      window.location.href = location.href + '?goindex=true'
    } else if (location.href.indexOf('?') !== -1 && location.href.indexOf('goindex') === -1) {
      window.location.href = location.href + '&goindex=true'
    }
  }
} 

router.beforeEach((to, from, next) => { 
  // 判断是否与BWRMApp打开，除却文章详情与error提示页面
  let ua = window.navigator.userAgent.toLowerCase();  
  let loadElement = document.getElementById("loadingBox");
  let _appKey = window.sessionStorage.getItem("appKey" ) ;
  let _jmsz = window.sessionStorage.getItem("jmsz" ) ;  
  // if(ua.indexOf("networking gang")<=-1){ 
  //   if(window.localStorage.test){ 
  //     if(!_appKey || !_jmsz){
  //       axios.post("soft/getWapConfig",{}).then(res =>{
  //         let resData = res.data ;
  //         window.sessionStorage.setItem("appKey" , resData.appKey) ;
  //         window.sessionStorage.setItem("jmsz" , resData.jmsz) ;  
  //         window.sessionStorage.setItem("adminWxNum",resData.adminWxNum) ;
  //         if (loadElement) {
  //           loadElement.style.display = "none"
  //         }
  //         next(); 
  //       })
  //     }else{   
  //       if (loadElement) {
  //         loadElement.style.display = "none"
  //       }
  //       next(); 
  //     }
  //     // next();  
  //     return false;
  //   }else if( to.path.indexOf("/adIndex/articleDetailWX")>-1){    
  //     if(!_appKey || !_jmsz){
  //       axios.post("soft/getWapConfig",{}).then(res =>{
  //         let resData = res.data ;
  //         window.sessionStorage.setItem("appKey" , resData.appKey) ;
  //         window.sessionStorage.setItem("jmsz" , resData.jmsz) ;  
  //         window.sessionStorage.setItem("adminWxNum",resData.adminWxNum) ;
  //         if (loadElement) {
  //           loadElement.style.display = "none"
  //         }
  //         next(); 
  //       })
  //     }else{  
  //       if (loadElement) {
  //         loadElement.style.display = "none"
  //       }
  //       next(); 
  //     }
  //     // next(); 
  //     return false;
  //   }else if( to.path.indexOf("error/404")<=-1 ){ 
  //     if (loadElement) {
  //       loadElement.style.display = "none"
  //     }
  //     next('/error/404') ;  
  //     return false;
  //   }
  // }
  // // 判断是否登录过期
  // if (!localStorage.uniqueId || (!localStorage.uniqueIdByInfluencer && localStorage.platformRole==2) ) {
  //   if (to.name.indexOf('Login')) { 
  //     if(!_appKey || !_jmsz){
  //       axios.post("soft/getWapConfig",{}).then(res =>{
  //         let resData = res.data ;
  //         window.sessionStorage.setItem("appKey" , resData.appKey) ;
  //         window.sessionStorage.setItem("jmsz" , resData.jmsz) ;  
  //         window.sessionStorage.setItem("adminWxNum",resData.adminWxNum) ;
  //         if (loadElement) {
  //           loadElement.style.display = "none"
  //         }
  //         next(); 
  //       })
  //     }else{  
  //       if (loadElement) {
  //         loadElement.style.display = "none"
  //       }
  //       next(); 
  //     }
  //     // next(); 
  //     return false;
  //   } else {  
  //     if (loadElement) {
  //       loadElement.style.display = "none"
  //     }
  //     Toast({
  //       message: '登录过期！',
  //       forbidClick: true,
  //       duration: 2000,
  //       onClose() { 
  //         if(localStorage.platformRole==2){
  //           window.location.replace(window.location.origin + "/#/infLogin/login");
  //         }else{
  //           window.location.reload() ;
  //         } 
  //       }
  //     });
  //   }
  // } else {   
  //   if(!_appKey || !_jmsz){
  //     axios.post("soft/getWapConfig",{}).then(res =>{
  //       let resData = res.data ;
  //       window.sessionStorage.setItem("appKey" , resData.appKey) ;
  //       window.sessionStorage.setItem("jmsz" , resData.jmsz) ;  
  //       window.sessionStorage.setItem("adminWxNum",resData.adminWxNum) ;
  //       //console.log(loadElement)
  //       if (loadElement) {
  //         loadElement.style.display = "none"
  //       }
  //       next(); 
  //     })
  //   }else{  
  //     if (loadElement) {
  //       loadElement.style.display = "none"
  //     }
  //     next(); 
  //   }
  //   // next(); 
  //   return false;
  // }
  axios.post("soft/getWapConfig",{}).then(res =>{
    let resData = res.data ;
    window.sessionStorage.setItem("appKey" , resData.appKey) ;
    window.sessionStorage.setItem("jmsz" , resData.jmsz) ;  
    window.sessionStorage.setItem("adminWxNum",resData.adminWxNum) ;
    if (loadElement) {
      loadElement.style.display = "none"
    }
    next(); 
  })
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app'); 